home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows (5th Edition) / Programming Windows, 5th ed. - Companion CD (097-0002183)(1999).iso / Chap17 / EndJoin / EndJoin.c next >
Encoding:
C/C++ Source or Header  |  1998-10-09  |  3.7 KB  |  113 lines

  1. /*----------------------------------------
  2.    ENDJOIN.C -- Ends and Joins Demo
  3.                 (c) Charles Petzold, 1998
  4.   ----------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  9.  
  10. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  11.                     PSTR szCmdLine, int iCmdShow)
  12. {
  13.      static TCHAR szAppName[] = TEXT ("EndJoin") ;
  14.      HWND         hwnd ;
  15.      MSG          msg ;
  16.      WNDCLASS     wndclass ;
  17.      
  18.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  19.      wndclass.lpfnWndProc   = WndProc ;
  20.      wndclass.cbClsExtra    = 0 ;
  21.      wndclass.cbWndExtra    = 0 ;
  22.      wndclass.hInstance     = hInstance ;
  23.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  24.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  25.      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  26.      wndclass.lpszMenuName  = NULL ;
  27.      wndclass.lpszClassName = szAppName ;
  28.      
  29.      if (!RegisterClass (&wndclass))
  30.      {
  31.           MessageBox (NULL, TEXT ("This program requires Windows NT!"),
  32.                       szAppName, MB_ICONERROR) ;
  33.           return 0 ;
  34.      }
  35.      
  36.      hwnd = CreateWindow (szAppName, TEXT ("Ends and Joins Demo"),
  37.                           WS_OVERLAPPEDWINDOW,
  38.                           CW_USEDEFAULT, CW_USEDEFAULT,
  39.                           CW_USEDEFAULT, CW_USEDEFAULT,
  40.                           NULL, NULL, hInstance, NULL) ;
  41.      
  42.      ShowWindow (hwnd, iCmdShow) ;
  43.      UpdateWindow (hwnd) ;
  44.      
  45.      while (GetMessage (&msg, NULL, 0, 0))
  46.      {
  47.           TranslateMessage (&msg) ;
  48.           DispatchMessage (&msg) ;
  49.      }
  50.      return msg.wParam ;
  51. }
  52.  
  53. LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  54. {
  55.      static int  iEnd[] = { PS_ENDCAP_ROUND, PS_ENDCAP_SQUARE, PS_ENDCAP_FLAT };
  56.      static int  iJoin[]= { PS_JOIN_ROUND,   PS_JOIN_BEVEL,    PS_JOIN_MITER } ;
  57.      static int  cxClient, cyClient ;
  58.      HDC         hdc ;
  59.      int         i ;
  60.      LOGBRUSH    lb ;
  61.      PAINTSTRUCT ps ;
  62.      
  63.      switch (iMsg)
  64.      {
  65.      case WM_SIZE:
  66.           cxClient = LOWORD (lParam) ;
  67.           cyClient = HIWORD (lParam) ;
  68.           return 0 ;
  69.           
  70.      case WM_PAINT:
  71.           hdc = BeginPaint (hwnd, &ps) ;
  72.           
  73.           SetMapMode (hdc, MM_ANISOTROPIC) ;
  74.           SetWindowExtEx (hdc, 100, 100, NULL) ;
  75.           SetViewportExtEx (hdc, cxClient, cyClient, NULL) ;
  76.           
  77.           lb.lbStyle = BS_SOLID ;
  78.           lb.lbColor = RGB (128, 128, 128) ;
  79.           lb.lbHatch = 0 ;
  80.           
  81.           for (i = 0 ; i < 3 ; i++)
  82.           {
  83.                SelectObject (hdc,
  84.                     ExtCreatePen (PS_SOLID | PS_GEOMETRIC |
  85.                                   iEnd [i] | iJoin [i], 10,
  86.                                   &lb, 0, NULL)) ;
  87.                BeginPath (hdc) ;
  88.                
  89.                MoveToEx (hdc, 10 + 30 * i, 25, NULL) ;
  90.                LineTo   (hdc, 20 + 30 * i, 75) ;
  91.                LineTo   (hdc, 30 + 30 * i, 25) ;
  92.                
  93.                EndPath (hdc) ;
  94.                StrokePath (hdc) ;
  95.                
  96.                DeleteObject (
  97.                     SelectObject (hdc,
  98.                          GetStockObject (BLACK_PEN))) ;
  99.                
  100.                MoveToEx (hdc, 10 + 30 * i, 25, NULL) ;
  101.                LineTo   (hdc, 20 + 30 * i, 75) ;
  102.                LineTo   (hdc, 30 + 30 * i, 25) ;
  103.           }
  104.           EndPaint (hwnd, &ps) ;
  105.           return 0 ;
  106.           
  107.      case WM_DESTROY:
  108.           PostQuitMessage (0) ;
  109.           return 0 ;
  110.      }
  111.      return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
  112. }
  113.